#include "QNoteListItemWidget.h"
#include <QDateTime>
#include <QDebug>

QNoteListItemWidget::QNoteListItemWidget(bool isDeleteMode)
    : m_bDeleteMode(isDeleteMode), m_bItemMarked(false)
{

}

QNoteListItemWidget::~QNoteListItemWidget()
{

}

MWidget * 	QNoteListItemWidget::createCell (const QModelIndex &index, MWidgetRecycler &recycler) const
{
	MNoteListItemWidget* m = new MNoteListItemWidget();
	QVariant data = index.data(Qt::DisplayRole);
	int noteptr = data.value<int>();
	Note* note = (Note*)(int*)noteptr;

	if(m_bDeleteMode)
		m->lDeleteMark->setVisible(true);
	else
	{
		if(note->resources.size() > 0)
			m->lDeleteMark->setPixmap(QPixmap(":/IconAdd/email_attachment.png"));
	}

	/* draw note tags */
	vector<string>::iterator it;
	QString tagList = 0;
	for(it = note->tagNames.begin(); it < note->tagNames.end(); it++)
	{
		tagList += QString((*it).c_str()) + " ";
	}

	if(tagList.size() == 0)
		m->lNoteTags->setText(QApplication::trUtf8("No tags"));
	else
		m->lNoteTags->setText(tagList);

	QString noteTitle = QString::fromUtf8(note->title.c_str());

	//TODO m->lNoteTitle->setStyleSheet("color: black");
	m->lNoteTitle->setText(noteTitle);
	m->lNoteDate->setText(QDateTime::fromTime_t(note->created / 1000).toString("M/d/yy h:m AP"));

	return m;
}

void 	QNoteListItemWidget::updateCell (const QModelIndex &index, MWidget *cell) const
{

}

QSizeF 	QNoteListItemWidget::cellSize () const
{
	return QSizeF(800, 70);
}
